package com.zjhn.ds.controller.pc;

import com.alibaba.fastjson.JSON;
import com.zjhn.ds.common.BizResult;
import com.zjhn.ds.common.PageBean;
import com.zjhn.ds.common.PageResult;
import com.zjhn.ds.domain.dto.pc.SpinnerDto;
import com.zjhn.ds.domain.dto.pc.WorkShopStationDto;
import com.zjhn.ds.domain.dto.pc.WorkshopClassDto;
import com.zjhn.ds.domain.dto.pc.WorkshopDto;
import com.zjhn.ds.param.AddUpdateClassParam;
import com.zjhn.ds.param.AddUpdateWorkshopParam;
import com.zjhn.ds.param.BindSpinnerParam;
import com.zjhn.ds.param.WorkshopRelPageParam;
import com.zjhn.ds.service.WorkshopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.controller.pc
 * @Author: sxt
 * @CreateTime: 2023-09-07  13:47
 * @Description: 车间相关接口
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/jlw/workshop")
@Api(tags = "pc端车间接口")
public class WorkshopController {

    @Resource
    private WorkshopService workshopService;

    @ApiOperation("新增/更新车间")
    @PostMapping("/addUpdate")
    public BizResult<?> addUpdate(@RequestBody @Valid AddUpdateWorkshopParam param) {
        log.info("====[INFO]=========WorkshopController====addUpdate param:{}", JSON.toJSONString(param));
        return workshopService.addUpdate(param);
    }

    @ApiOperation("删除车间")
    @GetMapping("/delete")
    public BizResult<?> delete(@RequestParam("workshop_id") String workshopId) {
        log.info("====[INFO]=========WorkshopController====delete workshopId:{}", workshopId);
        return workshopService.delete(workshopId);
    }

    @ApiOperation("分页查询车间信息")
    @PostMapping("/page")
    public BizResult<PageResult<WorkshopDto>> page(@RequestBody @Valid PageBean param) {
        log.info("====[INFO]=========WorkshopController====page param:{}", JSON.toJSONString(param));
        return workshopService.page(param);
    }

    @ApiOperation("分页查询车间挡车工信息")
    @PostMapping("/spinnerPage")
    public BizResult<PageResult<SpinnerDto>> spinnerPage(@RequestBody @Valid WorkshopRelPageParam param) {
        log.info("====[INFO]=========WorkshopController====spinnerPage param:{}", JSON.toJSONString(param));
        return workshopService.spinnerPage(param);
    }

    @ApiOperation("车间删除挡车工")
    @GetMapping("/removeSpinner")
    public BizResult<?> removeSpinner(@RequestParam("spinner_id") String spinnerId) {
        log.info("====[INFO]=========WorkshopController====removeSpinner spinnerId:{}", spinnerId);
        return workshopService.removeSpinner(spinnerId);
    }

    @ApiOperation("车间绑定挡车工")
    @PostMapping("/bindSpinner")
    public BizResult<?> bindSpinner(@RequestBody @Valid BindSpinnerParam param) {
        log.info("====[INFO]=========WorkshopController====bindSpinner param:{}", JSON.toJSONString(param));
        return workshopService.bindSpinner(param);
    }

    @ApiOperation("分页查询车间工位信息")
    @PostMapping("/stationPage")
    public BizResult<PageResult<WorkShopStationDto>> stationPage(@RequestBody @Valid WorkshopRelPageParam param) {
        log.info("====[INFO]=========WorkshopController====stationPage param:{}", JSON.toJSONString(param));
        return workshopService.stationPage(param);
    }

    @ApiOperation("获取车间班次时间表")
    @GetMapping("/getWorkshopClass")
    public BizResult<List<WorkshopClassDto>> getWorkshopClass(@RequestParam("workshop_id") String workshopId) {
        log.info("====[INFO]=========WorkshopController====getWorkshopClass workshopId:{}", workshopId);
        return workshopService.getWorkshopClass(workshopId);
    }

    @ApiOperation("车间删除班次")
    @GetMapping("/removeWorkshopClass")
    public BizResult<?> removeWorkshopClass(@RequestParam("workshop_class_id") String workshopClassId) {
        log.info("====[INFO]=========WorkshopController====removeWorkshopClass workshopClassId:{}", workshopClassId);
        return workshopService.removeWorkshopClass(workshopClassId);
    }

    @ApiOperation("新增/修改车间班次信息")
    @PostMapping("/addUpdateClass")
    public BizResult<?> addUpdateClass(@RequestBody @Valid AddUpdateClassParam param) {
        log.info("====[INFO]=========WorkshopController====addUpdateClass param:{}", JSON.toJSONString(param));
        return workshopService.addUpdateClass(param);
    }

}
